package com.cy.app.test;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.cy.app.R;
import com.cy.app.main.MainActivity;

public class PrintActivity extends Activity {

    private static final int PICK_PDF_REQUEST = 1;
    private Button printButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_print);

        printButton = findViewById(R.id.print_button);
        printButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 打开系统文件选择器，选择PDF文件
                Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                intent.setType("application/pdf");
                startActivityForResult(intent, PICK_PDF_REQUEST);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == PICK_PDF_REQUEST && resultCode == RESULT_OK && data!= null) {
            Uri pdfUri = data.getData();
            if (pdfUri!= null) {
                // 调用工具类方法进行PDF打印
                PdfPrintUtil.printPdf(PrintActivity.this, pdfUri);
            }
        }
    }
}